import {MyMapOpt} from "@/class/map/myMapOpt";
import {reqDeleteLayer, reqGetLayer, reqUpdateLayer, reqUploadLayer} from "@/api/Layer";
import {requestGetData, requestIsSuccess} from "@/api/request";

export class Layer{
    constructor({id,url,name,coordsys}) {
        this.id=id
        this.url=url
        this.name=name
        this.coordsys=coordsys||MyMapOpt.MapCoordSys.CJ02
    }
    upload(){
        return reqUploadLayer(this)
    }
    update(){
        return reqUpdateLayer(this)
    }
    delete(){
        return reqDeleteLayer(this.id)
    }
    static async getLayer() {
        let result = await reqGetLayer()
        let layerList = []
        if(requestIsSuccess(result)){
            requestGetData(result).forEach(item=>{
                layerList.push(new Layer(item))
            })
        }
        return layerList
    }
}